/*
 *  您可以更改此项目但请不要删除作者署名谢谢，否则根据中华人民共和国版权法进行处理.
 *  You may change this item but please do not remove the author's signature,
 *  otherwise it will be dealt with according to the Copyright Law of the People's Republic of China.
 *
 *  如果需要联系到我请加Wechat: yangbuyiya 备注交流学习
 *  If you need to contact me, please add Wechat: yangbuyiya as a note to exchange and learn.
 *  yangbuyi Copyright (c) https://yby6.com 2024.
 */

package com.yby6.config;


import com.yby6.config.properties.YuanQiSDKConfigProperties;
import com.yby6.yuanqi.sdk.session.YuanQiConfiguration;
import com.yby6.yuanqi.sdk.session.YuanQiSession;
import com.yby6.yuanqi.sdk.session.defaults.DefaultYuanQiSessionFactory;
import lombok.extern.slf4j.Slf4j;
import okhttp3.logging.HttpLoggingInterceptor;
import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Inject;

/**
 * yuanQiSession 工厂配置开启
 *
 * @author Yang Shuai
 * Create By 2024/06/26
 */
@Slf4j
@Configuration
public class YuanQiSDKConfig {

    @Bean
    public YuanQiSession yuanQiSession(@Inject YuanQiSDKConfigProperties properties) {

        log.info("元器SDK基础配置: {}", properties.toString());

        // 1. 配置文件
        YuanQiConfiguration configuration = new YuanQiConfiguration();
        configuration.setApiHost(properties.getApiHost());
        configuration.setApiKey(properties.getApiKey());
        configuration.setLevel(HttpLoggingInterceptor.Level.HEADERS);
        // 2. 会话工厂
        DefaultYuanQiSessionFactory factory = new DefaultYuanQiSessionFactory(configuration);

        // 3. 开启会话
        return factory.openSession();
    }

}
